package com.dmgis.hndz.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.dmgis.hndz.pojo.Ggsy02a;
import org.apache.ibatis.annotations.*;

import java.io.Serializable;
import java.util.List;

@Mapper
public interface Ggsy02aMapper extends BaseMapper<Ggsy02a> {

    @Select("SELECT * FROM ggsy02a WHERE ggsy02a060 = '0' and length(ggsy02a090) < 7  ORDER BY ggsy02a030 ")
    List<Ggsy02a> getProDept();

    @Select("SELECT * FROM ggsy02a WHERE ggsy02a060 = '0' and length(ggsy02a090) > 2 and length(ggsy02a090) < 10 ORDER BY ggsy02a030 ")
    List<Ggsy02a> getCityDept();

    @Select("SELECT * FROM ggsy02a WHERE ggsy02a060 = '0' and length(ggsy02a090) > 4 and length(ggsy02a090) < 13 ORDER BY ggsy02a030 ")
    List<Ggsy02a> getCountyDept();

    /**
     * 查询市级部门或县级部门
     *
     * @param advcode 行政编码
     * @return
     */
    List<Ggsy02a> getCityOrCountyDept(String advcode);

    @Insert("INSERT INTO ggsy02a" +
            "        (ggsy02a010, ggsy02a020, ggsy02a030, ggsy02a040, ggsy02a070, ggsy02a080," +
            "         ggsy02a090, ggsy02a100, ggsy02a110, ggsy02a120, ggsy02a130, ggsy02a140, ggsy02a150, ggsy02a160," +
            "         ggsy02a170, ggsy02a180, ggsy02a190, ggsy02a200, ggsy02a210, ggsy02a220, ggsy02a230, ggsy02a240," +
            "         ggsy02a250, ggsy02a260, ggsy02a270)" +
            "        VALUES" +
            "            (#{ggsy02a010}, #{ggsy02a020}, #{ggsy02a030}, #{ggsy02a040}, #{ggsy02a070}, #{ggsy02a080}," +
            "             #{ggsy02a090}, #{ggsy02a100}, #{ggsy02a110}, #{ggsy02a120}, #{ggsy02a130}, #{ggsy02a140}, #{ggsy02a150}, #{ggsy02a160}," +
            "             #{ggsy02a170}, #{ggsy02a180}, #{ggsy02a190}, #{ggsy02a200}, #{ggsy02a210}, #{ggsy02a220}, #{ggsy02a230}, #{ggsy02a240}," +
            "             #{ggsy02a250}, #{ggsy02a260}, #{ggsy02a270})")
    @Override
    int insert(Ggsy02a entity);

    @Update("UPDATE ggsy02a SET ggsy02a060 = '1' WHERE ggsy02a010 = #{id}::bigint")
    @Override
    int deleteById(Serializable id);

    @Update("UPDATE ggsy02a" +
            "        SET" +
            "            ggsy02a020 = #{ggsy02a020}," +
            "            ggsy02a030 = #{ggsy02a030}," +
            "            ggsy02a050 = #{ggsy02a050}," +
            "            ggsy02a070 = #{ggsy02a070}," +
            "            ggsy02a080 = #{ggsy02a080}," +
            "            ggsy02a090 = #{ggsy02a090}," +
            "            ggsy02a100 = #{ggsy02a100}," +
            "            ggsy02a110 = #{ggsy02a110}," +
            "            ggsy02a120 = #{ggsy02a120}," +
            "            ggsy02a130 = #{ggsy02a130}," +
            "            ggsy02a140 = #{ggsy02a140}," +
            "            ggsy02a150 = #{ggsy02a150}," +
            "            ggsy02a160 = #{ggsy02a160}," +
            "            ggsy02a170 = #{ggsy02a170}," +
            "            ggsy02a180 = #{ggsy02a180}," +
            "            ggsy02a190 = #{ggsy02a190}," +
            "            ggsy02a200 = #{ggsy02a200}," +
            "            ggsy02a210 = #{ggsy02a210}," +
            "            ggsy02a220 = #{ggsy02a220}," +
            "            ggsy02a230 = #{ggsy02a230}," +
            "            ggsy02a240 = #{ggsy02a240}," +
            "            ggsy02a250 = #{ggsy02a250}," +
            "            ggsy02a260 = #{ggsy02a260}," +
            "            ggsy02a270 = #{ggsy02a270}" +
            "        WHERE ggsy02a010 = #{ggsy02a010}")
    @Override
    int updateById(Ggsy02a entity);

    @Select("SELECT ggsy02a010, ggsy02a020, ggsy02a030, ggsy02a040, ggsy02a050, ggsy02a060, ggsy02a070, ggsy02a080," +
            "        ggsy02a090, ggsy02a100, ggsy02a110, ggsy02a120, ggsy02a130, ggsy02a140, ggsy02a150, ggsy02a160," +
            "        ggsy02a170, ggsy02a180, ggsy02a190, ggsy02a200, ggsy02a210, ggsy02a220, ggsy02a230, ggsy02a240," +
            "        ggsy02a250, ggsy02a260, ggsy02a270" +
            " FROM ggsy02a " +
            "WHERE ggsy02a010 = #{id}::bigint ")
    @Override
    Ggsy02a selectById(@Param("id") Serializable id);

    /**
     * 根据部门名称获取部门id
     *
     * @param ggsy02a020 部门名称
     * @return
     */
    @Select("SELECT ggsy02a010" +
            " FROM ggsy02a " +
            " WHERE ggsy02a020 = #{ggsy02a020}" +
            " LIMIT 1")
    Long selectGgsy02a010ByGgsy02a020(String ggsy02a020);
}

